<template>
    {{#if ctrl.psSysPFPlugin}}
    {{> @macro/plugins/widget/widget-use.hbs appPlugin=ctrl.psSysPFPlugin}}
    {{else}}
    <AppForm ref="editForm" :name="model.codeName" :class="classNames" :id="controlID"
        style="{{#if ctrl.width}}width: {{ctrl.width}}px;{{/if}}{{#if ctrl.height}}height: {{ctrl.height}}px;{{/if}}">
        <AppRow class="control-content app-control-form__content">
            {{#if ctrl.noTabHeader}}
                {{#each ctrl.psDEFormPages as | ctrlPage | }}
                {{#each ctrlPage.psDEFormDetails as | formDetail | }}
            {{> @macro/widgets/form-detail/include-form.hbs type=formDetail.detailType item=formDetail}}
                {{/each }}
                {{/each}}
            {{else}}
            <van-tabs class="app-control-form__page" >
                {{#each ctrl.psDEFormPages as | ctrlPage | }}
                {{> @macro/widgets/form-detail/include-form.hbs type=ctrlPage.detailType item=ctrlPage}}
                {{/each}}
            </van-tabs>
            {{/if}}
        </AppRow>
    </AppForm>
    {{/if}}
</template>
<script setup lang="ts">
{{> @macro/plugins/widget/widget-import.hbs ctrl=ctrl}}
{{> @macro/plugins/editor/editor-import.hbs}}
{{#if ctrl.psDEFormPages}}
{{#each ctrl.psDEFormPages as | FormPage | }}
{{> @macro/widgets/form-detail/include-form.hbs type="FORMMDCTRLIMPORT" item=FormPage}}
{{/each}}
{{/if}}
import { Ref } from 'vue';
import { AppForm, AppFormPage, AppFormGroup, AppFormTabPage, AppFormItem, AppFormButton, AppFormDruipart, AppFormIframe, AppFormRaw, AppFormMdCtrl, AppFormMdCtrlRepeater } from '@components/widgets/form';
import { model } from './{{spinalCase ctrl.codeName}}-form-model';
import { {{pascalCase ctrl.name }}ControlVO } from './{{spinalCase ctrl.codeName}}-form-vo';
import { EditFormActionType, EditFormController, IContext, IEditFormAbility, IEditFormControllerParams, IEditFormStore, IParam, ICtrlDataAction, IEditFormController, createUUID, ILoadingHelper, IViewCtx, IEvent } from '@/core';
import { useNavParamsBind, useEventBind, handleComponentAction, getCtrlClassNames } from '@/hooks/use-ctrl';
import FormService from "@/core/modules/ctrl-service/form-service";
{{> @macro/widgets/ctrl/ctrl-props.hbs
    props="openView?: Function;
    newView?: Function;
    actions: ICtrlDataAction;
    autoLoad?: boolean;
    isEditable?: boolean;
    "
    propsDefault="isEditable: false,
    autoLoad: false,"
}}

{{> @macro/common/emit.hbs name="ctrl" actionType="EditFormActionType" ability="IEditFormAbility"}}

const editForm: Ref = ref(null);

const controlID = createUUID();

const classNames = computed(() => {
    return getCtrlClassNames(model, props);
});

const { entityCodeName, keyPSAppDEField, majorPSAppDEField } = model;

const ctrlService = new FormService<{{pascalCase ctrl.name}}ControlVO>({{pascalCase ctrl.name}}ControlVO, model.entityCodeName);
//  表单控制器
const params: IEditFormControllerParams<EditFormActionType, IEditFormAbility> = {
    name: props.name,
    model,
    evt,
    controlID,
    autoLoad: props.autoLoad,
    isEditable: props.isEditable,
    pLoadingHelper: props.pLoadingHelper,
    actions: props.actions,
    openView: props.openView,
    newView: props.newView,
    closeView: props.closeView,
    ctrlService: ctrlService,
    formValidate: async (name?: string) => { return await editForm.value.formValidate(name) },
    handler: (data: IEditFormStore) => { return reactive(data) }
};
{{> @macro/common/controller.hbs name="ctrl" IController="IEditFormController" store="IEditFormStore" ability="IEditFormAbility" controller="EditFormController"}}
</script>